Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

693
Visualizações
error: column "..." of relation "..." does not exist

I'm using PostgreSQL with Sequelize in Nodejs. There are 3 tables: tc_user_intervention, tc_interventions and tc_users. tc_user_intervention has 2 fields: userid (from tc_users) and interventionid (from tc_interventions). Here's the Sequelize model (auto-generated from the existing database):

const UserIntervention =  sequelize.define('tc_user_intervention', {
    userid: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: 'tc_users',
        key: 'id'
      }
    },
    interventionid: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: 'tc_interventions',
        key: 'id'
      }
    }
  }, {
    sequelize,
    tableName: 'tc_user_intervention',
    schema: 'public',
    timestamps: false
  });

If I try to do a raw query, everything works, I can insert a new raw into tc_user_interventions:

INSERT INTO `tc_user_intervention`
VALUES (value1, value2);

But if I try to do the same query with Sequelize, I receive the error:

 error: column "id" of relation "tc_user_intervention" does not exist

The query simply is:

UserIntervention.create({ 'userid': user, 'interventionid': intervention});

But Sequelize translate this query into:

sql:
      'INSERT INTO "public"."tc_user_intervention" ("id","userid","interventionid") VALUES (DEFAULT,$1,$2) RETURNING "id","userid","interventionid";',

and obviously this give me the error, because the id column does not exist neither in the model nor in the database. Why is this happening?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda